//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//


#include "GenericPropClasses.hpp"
#include <Pm.h>

CGenericPropPage::CGenericPropPage (CGenericPropSheet *pOwner) : CPropPage(pOwner)
{
    if(pOwner->GetWizardFlag())
		m_pWbtWiz = pOwner->GetWbtWiz();
}

CGenericPropPage::~CGenericPropPage()
{
	//DEBUGMSG(1,(L"CGenericProppage destructor"));
	if(GetOwner().GetWizardFlag())
		m_pWbtWiz = NULL;
}

BOOL CGenericPropPage::ReadRegistrySettings()
{
	// not implemented
	return FALSE;
}

BOOL CGenericPropPage::WriteRegistrySettings()
{
	// not implemented
	return FALSE;
}

BOOL CGenericPropPage::LoadPage()
{
	return ReadRegistrySettings();
}


BOOL CGenericPropPage::UnloadPage()
{
	// save settings only if our page became active at some point
	if (Activated())
		return WriteRegistrySettings();
	else
	{
		//DEBUGMSG (1, (L"UnloadPage(): Page [%s] never became active\n", GetId()));
		return FALSE;
	}

}

CGenericPropSheet& CGenericPropPage::GetOwner()
{
	//return dynamic_cast<CGenericPropSheet&> (CPropPage::GetOwner());
	return (CGenericPropSheet&) CPropPage::GetOwner();
}

CGenericPropSheet::CGenericPropSheet (HINSTANCE hInstance, HWND hwndParent, LPCTSTR szTitle) :
		CPropSheet (hInstance,hwndParent, szTitle, FALSE, FALSE), m_bSetDefaults (FALSE), m_bReboot (FALSE),m_bWizardFlag(FALSE)
{
}
CGenericPropSheet::CGenericPropSheet (HINSTANCE hInstance, HWND hwndParent, TsWbtWizard *pWbtWiz, LPCTSTR szTitle) :
		CPropSheet (hInstance, hwndParent, szTitle, FALSE, TRUE), m_pWbtWiz (pWbtWiz),m_bWizardFlag(TRUE)
{
}

CGenericPropSheet::~CGenericPropSheet()
{
}


void CGenericPropSheet::OnKillActivePage (CPropPage *pPage)
{
	// right now we don't know if this is due to the 'OK' button
	// or simply switching tabs

	if (pPage)
	{
		//DEBUGMSG (1, (L"Page [%s] becoming inactive\n", pPage->GetId()));

		// call the page's unload function
		pPage->UnloadPage();
	}
}

void CGenericPropSheet::SetDefaults(BOOL bDefault)
{
	m_bSetDefaults = bDefault;
}

void CGenericPropSheet::SetReboot(BOOL bReboot)
{
	m_bReboot = bReboot;
}


BOOL CGenericPropSheet::GetDefaults()
{
	return m_bSetDefaults;
}

BOOL CGenericPropSheet::GetReboot()
{
	return m_bReboot;
}

BOOL CGenericPropSheet::GetWizardFlag()
{
	return m_bWizardFlag;
}

void CGenericPropSheet::WriteSettings()
{
	if(!GetWizardFlag())
	{
		if (GetReboot())
		{
			LPCWSTR pszCaption = (LPCWSTR )LoadString(GetInstance(), IDS_RESTART_CAPTION, NULL, 0);
			LPCWSTR pszMsg = (LPCWSTR )LoadString(GetInstance(), IDS_RESTART_MSG, NULL, 0);

			if ((pszCaption) && (pszMsg) && (MessageBox(NULL,pszMsg,pszCaption,MB_YESNO|MB_TOPMOST) == IDYES) )
			{
				SetSystemPowerState(NULL, POWER_STATE_RESET, POWER_FORCE);
			}

		}
	}
}



